<?php
/**
 * 
 * Esta es la clase modelo del Modulo Control de Usuario
 * @author Rosanna Paberli Jimenez Rosario
 *
 */
class ModuloModel extends Model
{
	private $_nameTable = "US_Modulos";
	
	public function __construct()
	{
		parent::Model();
	}
	
	public function loadRegistro($start = NULL, $offset = NULL, $sortname = NULL, $sortorder = NULL)
	{
		 if($offset != false){
               $this->db->limit($offset, $start);
         }
		      
		 if($sortname != false && $sortorder != false){
		        $this->db->order_by($sortname, $sortorder);
		 }
		 
		$query = $this->db->get($this->_nameTable);
		return $this->_getArrayFromQueryResult($query);
	}
	
	public function loadRegistroById($id)
	{
		$query = $this->db->get_where($this->_nameTable, array('id_modulos' => $id));
		
		if($query->num_rows() == 0)
			return false;
		
			return new UsModulo($query->row());
		
	}
	
	private function _getArrayFromQueryResult($resurt)
	{
		if($resurt->num_rows() == 0){
			return false;
		}
		
		$registros = array();
		
		foreach($resurt->result() as $record){
			$registros[] = new UsModulo($record);
		}
		
		return $registros;
	}
	
	public function addRegistro($data)
	{
		 if($this->db->insert($this->_nameTable, $data)){
		 	return true;
		 }
		 	return false;
	}
	
	public function upDateRegistro($data, $id)
	{	
		if($this->db->update($this->_nameTable, $data, array('id_modulos' => $id))){
			return true;
		}
			return false;
	}
	
	public function deleteRegistro($id)
	{
		if($this->db->delete($this->_nameTable, array("id_modulos" => $id))){
		}
	}
}

class UsModulo
{
	private $_idModulos = 0;
	private $_detalleModulo = "";
	
	public function __construct($dataObjeto)
	{
		$this->_idModulos = $dataObjeto->id_modulos;
		$this->_detalleModulo = $dataObjeto->detalle_modulo;
	}
	
	public function getIdModulos()
	{
		return $this->_idModulos;
	}
	
	public function getDetalleModulo()
	{
		return $this->_detalleModulo;
	}
}